YAHOO.namespace("example.container");

YAHOO.util.Event.onDOMReady(function () {
	
	var handleSubmit = function() {
		this.submit();
	};
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
	};
	
	var handleFailure = function(o) {		
	};

    YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");

	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "30em",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"Tweet", handler:handleSubmit, isDefault:true },
								      { text:"Close", handler:handleCancel } ]
							});

	YAHOO.example.container.dialog1.validate = function() {
		var data = this.getData();
		
		var check = true;
		if (data.username == "" || data.password == "")
		{
			check = false;
			alert("Wrong username or password!");			
		}
		else check = true;
		
		if (data.tweet.length >= 140 )
		{
			check = false;
			alert("Tweet length should be less than 140 symbols!");			
		}
		else check = true;
		
		return check;
	};

	YAHOO.example.container.dialog1.callback = { success: handleSuccess,
						     failure: handleFailure };
	
	YAHOO.example.container.dialog1.render();

	YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
});

document.documentElement.className = "yui-pe";